<?php
namespace app\index\controller;

use app\member\model\MemberAddress;
use app\index\model\Region;
use think\Session;
use app\warehouse\model\Carrier;

class Trade extends User
{
    // 下单成功
    public function finish()
    {
        return $this->fetch();
    }

    // 提交失败
    public function fail()
    {
        return $this->fetch();
    }

    // 订单确认页
    public function confirm()
    {
        $this->assign('cart_title', '确认订单信息页');

        //收货地址
        $addressModel = new MemberAddress();
        $addressList = $addressModel->getAddress($this->mid,5);
        $this->assign('addressList', $addressList);

        //区域
        $regionModel = new Region();
        $region = $regionModel->getAll();
        $this->assign('region', $region);

        //物流
        $carrierModel = new Carrier();
        $carrierList = $carrierModel->getAllList();
        $this->assign('carrierList', $carrierList);
        //dump($carrierList);

        //是否分单
        $goodsId = Session::get('goodsId');
        if(empty($goodsId)) return false;

        $goodsIdArr = explode(',', $goodsId);
        //dump($goodsIdArr);
        $cartModel = new Cart();
        $list = model('Cart')->getCartData($this->member,$goodsIdArr);
        $key = array_keys($list);
        $shopNum = isset($list[0]) ? count($list[0]['shop']) : 0; //第三方店铺数量
        if(count($key)>1 || $shopNum>1){
            $view = 'trade/more/confirm';
        }else{
            $view = 'confirm';
        }
        $this->assign('list', $list);

        return $this->fetch($view);
    }

    // 创建订单
    public function create()
    {
        return $this->fetch();
    }

    // 关闭layout
    public function test()
    {
        $this->view->engine->layout(false);
        $this->assign('name', 'feng');
        return $this->fetch('test');
    }
}